/*
 * Copyright (c) 2023-2025 elsfs Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.elsfs.cloud.common.mybatis.ext.db;

import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/** 通用SQL执行器 */
public interface GenericSqlExecutorMapper {

  /** SQL参数名称 */
  String SQL_PARAMETER_NAME = "vefGenericSql";

  /** SQL占位符 */
  String SQL_PLACEHOLDER_NAME = "${" + SQL_PARAMETER_NAME + "}";

  /** 分页SQL参数名称前缀 */
  String PAGE_SQL_PARAMETER_NAME_PREFIX = "params.";

  /** 分页SQL占位符 */
  String PAGE_SQL_PLACEHOLDER_NAME =
      "${" + PAGE_SQL_PARAMETER_NAME_PREFIX + SQL_PARAMETER_NAME + "}";

  /**
   * 查询单条数据
   *
   * @param params 参数
   * @return 结果
   */
  @Select(SQL_PLACEHOLDER_NAME)
  Map<String, Object> selectOne(Map<String, Object> params);

  /**
   * 查询列表数据
   *
   * @param params 参数
   * @return 结果
   */
  @Select(SQL_PLACEHOLDER_NAME)
  List<Map<String, Object>> selectList(Map<String, Object> params);

  /**
   * 查询分页数据
   *
   * @param page 分页对象
   * @param params 参数
   * @return 结果
   */
  @Select(PAGE_SQL_PLACEHOLDER_NAME)
  IPage<Map<String, Object>> selectPage(IPage<?> page, Map<String, Object> params);

  /**
   * 插入数据
   *
   * @param params 参数
   * @return 结果
   */
  @Insert(SQL_PLACEHOLDER_NAME)
  int insert(Map<String, Object> params);

  /**
   * 更新数据
   *
   * @param params 参数
   * @return 结果
   */
  @Update(SQL_PLACEHOLDER_NAME)
  int update(Map<String, Object> params);

  /**
   * 删除数据
   *
   * @param params 参数
   * @return 结果
   */
  @Delete(SQL_PLACEHOLDER_NAME)
  int delete(Map<String, Object> params);
}
